﻿using System.Runtime.Serialization;
using XcoAppSpaces.Contracts.Messaging;

namespace XcoAppSpaces.Serialization.Binary
{
	class CausalityContextSerializationSurrogate : ISerializationSurrogate
	{
		public void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
		{
			var msg = (CausalityContext)obj;
			info.AddValue("Causalities", msg.Causalities);
		}

		public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
		{
			obj = new CausalityContext((CausalityInfo[])info.GetValue("Causalities", typeof(CausalityInfo[])));
			return obj;
		}
	}
}